//
//  AppDelegate.m
//  UI13_1_UITabBarController标签控制器
//
//  Created by Scott on 15/5/12.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"
#import "FiveViewController.h"
#import "SixViewController.h"

@interface AppDelegate () <UITabBarControllerDelegate>

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
#pragma mark - 知识点1 UITabBarController 标签控制器 
    /* 定义6个视图控制器, 创建视图控制器对象 */
    FirstViewController *first = [[FirstViewController alloc] init];
    

    SecondViewController *second = [[SecondViewController alloc] init];
       /* 将第2个界面加到一个NavigationController 中 */
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:second];
    
    
    ThirdViewController *third = [[ThirdViewController alloc] init];

    
    FouthViewController *fouth = [[FouthViewController alloc] init];

    
    FiveViewController *five = [[FiveViewController alloc] init];

    
    SixViewController *six = [[SixViewController alloc] init];
    
    
    /* 创建UITabBarController对象 */
    UITabBarController *tabBC = [[UITabBarController alloc] init];
    
    /* 给 tabBarController 指定一个viewController 数组 */
    tabBC.viewControllers = @[first, navi, third, fouth, five];
    
    /* tabBarContoller 指定delegate */
    tabBC.delegate = self;
    
    /* tabBar 颜色 */
    tabBC.tabBar.barTintColor = [UIColor redColor];
    
    /* tabBar 字体颜色 */
    tabBC.tabBar.tintColor = [UIColor orangeColor];
    
    
    /* 设置 window 主视图控制器 */
    self.window.rootViewController = tabBC;
    
    [tabBC release];
    [first release];
    [second release];
    [navi release];
    [third release];
    [fouth release];
    [five release];
    [six release];
    [_window release];
    return YES;
}

#pragma mark ** UITabBarControllerDelegate 协议方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"%ld", tabBarController.selectedIndex);
    
    /* 当选中时, 徽章计数清零 */
    tabBarController.selectedViewController.tabBarItem.badgeValue = nil;
    
}


#pragma mark -
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
